/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

using ll = long long;

constexpr int maxn = 5e3;

ll sum[maxn + 1], f[maxn + 1];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sum[i];
    sum[i] += sum[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < i; ++j) {
      int d = i - j;
      f[i] = std::max(
          f[i], f[j] + (d & 1 ? sum[d / 2] * 2 : sum[d / 2] + sum[d / 2 - 1]));
    }
  }
  cout << f[n];
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("E - Work or Rest.in", "r", stdin);
  freopen("E - Work or Rest.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
